home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.07 Jul 94 / Multiple Monitors < prev    next >
Encoding:
Text File  |  1994-06-16  |  3.2 KB  |  145 lines  |  [TEXT/ttxt]

  1.     if ( gHasColorQuickDraw )
  2.         limitR = (**GetGrayRgn()).rgnBBox;
  3.     else
  4.         limitR = screenBits.bounds;
  5.  
  6.     DragWindow( myWindow, theEvent->where, &limitR );
  7.  
  8.  
  9. ______
  10.  
  11. /*
  12.     IsPositionOK
  13.     
  14.     Description:
  15.     Checks to make sure the passed global rectangle is completely contained within the
  16.     gray region. Pass the window’s portRect in global coordinates.
  17.  
  18.     Notes:
  19.     Depends on two regions, gSpareRgn1 and gSpareRgn2, having been allocated
  20.     globally (using NewRgn).
  21.      
  22.     Your application might want to allow partially offscreen windows. 
  23.     
  24.     Document windows are assumed to have title heights of 20 pixels. There are more
  25.     dynamic ways of handling this, such as positioning the window way offscreen and
  26.     checking its structure region. 
  27. */
  28. Boolean IsPositionOK( Rect *globalR, Boolean isDocWindow )
  29. {
  30.     Boolean    isOK = false;
  31.     Rect        fullWindowR;
  32.      
  33.     #define kDocWindowHeight    20        // pixels
  34.         
  35.     // put the window rect into gSpareRgn1
  36.     fullWindowR = *globalR;
  37.     if ( isDocWindow )
  38.         fullWindowR.top -= kDocWindowHeight;
  39.     RectRgn( gSpareRgn1, &fullWindowR );
  40.     
  41.     // see if the window completely intersects the grayRgn
  42.     SectRgn( GetGrayRgn(), gSpareRgn1, gSpareRgn2 );
  43.     if ( EqualRgn( gSpareRgn1, gSpareRgn2 ) )
  44.         isOK = true;
  45.     
  46.     return( isOK );
  47. }
  48.  
  49.  
  50. _________
  51.  
  52. /*
  53.     FindDeviceThatSupportsDepth
  54.     
  55.     Returns:
  56.     The GDHandle for a device that supports the passed depth.
  57.     Returns nil if no device found or no color quickdraw.
  58.  
  59.     Notes:
  60.     Requires System 6.05 or later.
  61. */
  62. GDHandle FindDeviceThatSupportsDepth( short theDepth )
  63. {
  64.     GDHandle    aScreen;
  65.     
  66.     if ( !gHasColorQuickDraw )
  67.         return( nil );
  68.  
  69.     // first check the main screen - it takes precedence
  70.     aScreen = GetMainDevice();
  71.     if ( DoesDeviceSupportDepth( aScreen, theDepth ) )
  72.         return( aScreen );
  73.         
  74.     // step through all the screens
  75.     aScreen = GetDeviceList();
  76.     
  77.     while ( aScreen )
  78.     {
  79.         if ( DoesDeviceSupportDepth( aScreen, theDepth ) )
  80.             return( aScreen );
  81.         aScreen = GetNextDevice( aScreen );
  82.     }
  83.  
  84.     return( nil );
  85. }
  86.  
  87. Boolean DoesDeviceSupportDepth( GDHandle theDevice, short theDepth )
  88. {
  89.     if (     IsDeviceActive( theDevice ) && 
  90.         HasDepth( theDevice, theDepth, 0/*whichFlags*/, 0 ) )
  91.         return( true );
  92.     else    
  93.         return( false );
  94. }
  95.  
  96. Boolean IsDeviceActive( GDHandle theDevice )
  97. {
  98.     if ( !theDevice )
  99.         return( false );
  100.  
  101.     /*
  102.         sometimes newly installed video cards show the main device
  103.         as inactive. we’ll make an extra check for this case.
  104.     */
  105.     if ( theDevice == GetMainDevice() )
  106.         return( true );        // main device is always active
  107.     
  108.     if (     TestDeviceAttribute( theDevice, screenDevice ) &&
  109.         TestDeviceAttribute( theDevice, screenActive ) )
  110.         return( true );
  111.     else
  112.         return( false );
  113. }
  114.  
  115.  
  116. _________
  117.  
  118. short FindWindowDepth( WindowPtr myWindow )
  119. {
  120.     Rect        r;
  121.     GDHandle    theDevice;
  122.     short        theDepth;
  123.     GrafPtr    oldPort;
  124.  
  125.     if ( !gHasColorQuickDraw )
  126.         return( 1 );                    // 1-bit if no color quickdraw
  127.  
  128.     GetPort( &oldPort );            // save old port
  129.     SetPort( myWindow );
  130.  
  131.     // get the window’s content rect in global coords
  132.     r = myWindow->portRect;        
  133.     LocalToGlobal( (Point*) &r );    
  134.     LocalToGlobal( 1 + (Point*) &r );
  135.  
  136.     // find the deepest device intersecting the window
  137.     theDevice = GetMaxDevice( &r );
  138.     theDepth = theDevice ? (**(**theDevice).gdPMap).pixelSize : 1;
  139.  
  140.     // color table is at: (**(**theDevice).gdPMap).pmTable
  141.  
  142.     SetPort( oldPort );            // restore port
  143.     return( theDepth );
  144. }
  145.